﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.IO;

public partial class CMS_Control_CacheView : System.Web.UI.UserControl
{
    Usas.BLL.Cms.cmsArticle art = new Usas.BLL.Cms.cmsArticle();
    Usas.BLL.Cms.cmsType ct = new Usas.BLL.Cms.cmsType();
    Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();
    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
    Usas.BLL.Cms.cms_purview_setting cps = new Usas.BLL.Cms.cms_purview_setting();

    Usas.BLL.Cms.AspPager ap = new Usas.BLL.Cms.AspPager();

    #region 外部属性
    private ShowMode _Type = ShowMode.Type;
    private ShowMode _Border = ShowMode.Border;
    private ShowMode _Article = ShowMode.Article;
    private ShowMode _ArticleSon = ShowMode.ArticleSon;
    private ShowMode _GetTop = ShowMode.GetTop;
    public enum ShowMode : int
    {
        Type = 1,
        Border = 2,
        Article = 3,
        ArticleSon = 4,
        GetTop = 5


    }

    public ShowMode Type
    {
        get
        {
            return _Type;
        }
        set
        {
            _Type = value;
        }
    }


    public ShowMode Border
    {
        get
        {
            return _Border;
        }
        set
        {
            _Border = value;
        }
    }

    public ShowMode Article
    {
        get
        {
            return _Article;
        }
        set
        {
            _Article = value;
        }
    }

    public ShowMode ArticleSon
    {
        get
        {
            return _ArticleSon;
        }
        set
        {
            _ArticleSon = value;
        }
    }

    public ShowMode GetTop
    {
        get
        {
            return _GetTop;
        }
        set
        {
            _GetTop = value;
        }
    }


    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 查询列表
    /// </summary>
    /// <param name="SM">类型</param>
    /// <param name="top">数量</param>
    /// <param name="where">条件</param>
    /// <param name="role">本人权限</param>
    /// <param name="typename">标题名</param>
    /// <param name="num">当前页</param>
    /// <param name="edit">是否编辑</param>
    public void OnlySearch(ShowMode SM, int top, string Type, string TypeName, ArrayList role, string where, string key, int num, string routerText, bool edit, bool NeedEdit, int ShowLength, string img)
    {
        DataTable dt = null;
        DataTable TopDt = null;
        int count = 0;
        dt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ((ArtFormat !=1 and PublishStatus=1) or (ArtFormat =1 and CanView=0)) and (IsVersion is null or IsVersion=0) " + where, num, top, "ArtOrder", out count);
        Bind(ShowMode.Article, Type, dt, TypeName, role, num, true, true, true, routerText, edit, ShowMode.ArticleSon, NeedEdit, ShowLength, TopDt, img);
        BindPager(count, dt, num, top);
    }

    /// <summary>
    /// 列表显示
    /// </summary>
    /// <param name="SM">类型</param>
    /// <param name="top">显示数量</param>
    /// <param name="Type">类型ID</param>
    /// <param name="role">本人权限</param>
    /// <param name="TypeName">标题</param>
    /// <param name="num">当前页</param>
    /// <param name="routerText">增加、编辑DIV标题</param>
    /// <param name="edit">是否编辑</param>
    public void GetCacheView(ShowMode SM, int top, string Type, ArrayList role, string TypeName, int num, string routerText, bool edit, bool NeedEdit, int ShowLength, string img)
    {
        DataTable dt = null;
        DataTable TopDt = null;
        int count = 0;

        switch (SM)
        {
            case ShowMode.Type:
                dt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ArtFormat !=1 and PublishStatus=1 and (IsVersion is null or IsVersion=0) and TypeId=" + Type, num, top, "ModfiyTime", out count);
                Bind(SM, Type, dt, TypeName, role, num, false, false, false, routerText, edit, SM, NeedEdit, ShowLength, TopDt, img);
                break;
            case ShowMode.Border:
                dt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ArtFormat !=1 and PublishStatus=1 and (IsVersion is null or IsVersion=0) and BorderId=" + Type, num, top, "ModfiyTime", out count);
                TopDt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ArtFormat !=1 and PublishStatus=1 and (IsVersion is null or IsVersion=0) and IsTop='222" + Type + "'", 1, -1, "ArtOrder");
                Bind(SM, Type, dt, TypeName, role, num, false, true, false, routerText, edit, SM, NeedEdit, ShowLength, TopDt, img);
                break;
            case ShowMode.Article:
                dt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ((ArtFormat !=1 and PublishStatus=1) or (ArtFormat =1 and CanView=0)) and (IsVersion is null or IsVersion=0) and BorderId=" + Type + " and ParentArtId=0", num, top, "ArtOrder", out count);
                TopDt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ArtFormat !=1 and PublishStatus=1 and (IsVersion is null or IsVersion=0) and IsTop='222" + Type + "'", 1, -1, "ArtOrder");
                BindPager(count, dt, num, top);
                Bind(SM, Type, dt, TypeName, role, num, true, true, true, routerText, edit, SM, NeedEdit, ShowLength, TopDt, img);
                break;
            case ShowMode.ArticleSon:
                //dt = ap.GetArticleTableBySetting("1=1","1=1",num, top, "ArtOrder", out count);

                dt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ((ArtFormat !=1 and PublishStatus=1) or (ArtFormat =1 and CanView=0)) and (IsVersion is null or IsVersion=0) and ParentArtId=" + Type, num, top, "ArtOrder", out count);
                TopDt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ArtFormat !=1 and PublishStatus=1 and (IsVersion is null or IsVersion=0) and IsTop='333" + Type + "'", 1, -1, "ArtOrder");
                BindPager(count, dt, num, top);
                Bind(ShowMode.Article, Type, dt, TypeName, role, num, true, true, true, routerText, edit, ShowMode.ArticleSon, NeedEdit, ShowLength, TopDt, img);
                break;
            case ShowMode.GetTop:
                dt = null;
                TopDt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), " ArtFormat !=1 and PublishStatus=1 and (IsVersion is null or IsVersion=0) and IsTop='" + Type + "'", 1, -1, "ArtOrder");
                if (TopDt == null || TopDt.Rows.Count <= 0)
                {
                    LitCacheView.Text = "";
                }
                else
                {
                    Bind(ShowMode.GetTop, Type, TopDt, TypeName, role, num, false, false, false, routerText, edit, SM, NeedEdit, ShowLength, dt, img);

                }
                break;
        }
    }


    private void Bind(ShowMode SM, string id, DataTable dt, string TypeName, ArrayList role, int num, bool Add, bool PartAdd, bool PartEdit, string routerText, bool edit, ShowMode ASM, bool NeedEdit, int ShowLength, DataTable DtTop, string img)
    {
        if (SM == ShowMode.GetTop)
        {
            LitCacheView.Text += "<div class=\"groupItem\" id=\"ViewListType" + id.ToString() + "\" >";
            LitCacheView.Text += "<div class=\"itemHeader\" style='border-top: red 2px solid;background-color: #eee;'> ";
        }
        else
        {
            LitCacheView.Text += "<div class=\"groupItem\" id=\"ViewListType" + id.ToString() + "\">";
            LitCacheView.Text += "<div class=\"itemHeader\"> ";
        }
        switch (SM)
        {
            case ShowMode.Type:
                LitCacheView.Text += "<img src='images/dir.gif' style='margin-top:3px;'/> <a href='ViewListBorder.aspx?id=" + id + "&check=" + ro.GetMd5Str(id + "check" +
                    edit.ToString()) + "' style='left:30px;font-weight:bold;font-size: 16px;' class='tplink'>" + TypeName + "</a>";
                break;
            case ShowMode.Border:
                LitCacheView.Text += "<img src='images/dir.gif' style='margin-top:3px;'/> <a href='ViewListArticle.aspx?bid=" + id + "&pid=0&check=" + ro.GetMd5Str(id + "check" +
                    edit.ToString()) + "' style='left:30px;font-weight:bold;font-size: 16px;' class='tplink'>" + TypeName + "</a>";
                break;
            case ShowMode.Article:
                LitCacheView.Text += "<img src='images/dir.gif' style='margin-top:3px;'/> " + TypeName;
                break;
            case ShowMode.GetTop:
                LitCacheView.Text += "<img src='images/top.gif' style='margin-top:3px;'/> <span style='color:red'>" + TypeName + "</span>";
                break;
        }

        if (NeedEdit)
        {
            if (edit)
            {
                if (PartEdit)
                {
                    switch (ASM)
                    {
                        case ShowMode.Article:
                            LitCacheView.Text += "<a href=\"javascript:void(0)\" onclick=\"LightBox('" + routerText + "[修改目录]','Admin/PartControl.aspx?action=edit&id=" + id + "&tid=b','750','420','',true);return false\" style='margin-right:160px;margin-top:3px;'><img src='images/folderedit.gif' border='0'/> 修改目录</a>";
                            break;
                        case ShowMode.ArticleSon:
                            LitCacheView.Text += "<a href=\"javascript:void(0)\" onclick=\"LightBox('" + routerText + "[修改目录]','Admin/PartControl.aspx?action=edit&id=" + id + "&tid=a','750','250','',true);return false\" style='margin-right:160px;margin-top:3px;'><img src='images/folderedit.gif' border='0'/> 修改目录</a>";
                            break;
                    }
                }
                if (PartAdd)
                {
                    switch (ASM)
                    {
                        case ShowMode.Border:
                            break;
                        case ShowMode.Article:
                            LitCacheView.Text += "<a href=\"javascript:void(0)\" onclick=\"LightBox('" + routerText + "> [添加子目录]','Admin/PartControl.aspx?action=add&id=" + id + "&tid=b','750','250','',true);return false\" style='margin-right:80px;margin-top:3px;'><img src='images/folderadd.gif' border='0'/> 添加目录</a>";

                            break;
                        case ShowMode.ArticleSon:
                            LitCacheView.Text += "<a href=\"javascript:void(0)\" onclick=\"LightBox('" + routerText + "> [添加子目录]','Admin/PartControl.aspx?action=add&id=" + id + "&tid=a','750','250','',true);return false\" style='margin-right:80px;margin-top:3px;'><img src='images/folderadd.gif' border='0'/> 添加目录</a>";

                            break;
                    }
                }

                if (Add)
                {
                    switch (ASM)
                    {
                        case ShowMode.Article:
                            LitCacheView.Text += "<a href=\"javascript:void(0)\" onclick=\"LightBox('" + routerText + "> [内容发布]','Admin/ViewControl.aspx?action=add&id=" + id +
                                 "&type=b','900','650','',true);return false\" style='margin-right:0px;margin-top:3px;'><img src='images/add.gif' border='0'/> 内容发布</a>";

                            break;
                        case ShowMode.ArticleSon:
                            LitCacheView.Text += "<a href=\"javascript:void(0)\" onclick=\"LightBox('" + routerText + "> [内容发布]','Admin/ViewControl.aspx?action=add&id=" + id +
                                "&type=a','900','650','',true);return false\" style='margin-right:0px;margin-top:3px;'><img src='images/add.gif' border='0'/> 内容发布</a>";
                            break;
                    }
                }
                LitCacheView.Text += "</div><div class=\"itemContent\">";
            }
            else
            {
                LitCacheView.Text += "</div><div class=\"itemContent\">";
            }
        }
        else
        {
            LitCacheView.Text += "</div><div class=\"itemContent\">";
        }

        string[] imgs = null;
        if (img != "")
        {
            imgs = img.Split(',');
            if (imgs[0] == "l")
            {
                LitCacheView.Text += "<table style='width:100%;' border='0' cellpadding='5'><tr><td style='width:200px;' valign='top'><img src=" + imgs[1] + " style='width:200px;height:150px;'></td><td  valign='top'><ul >";
            }
            else
            {
                LitCacheView.Text += "<table style='width:100%' border='0' cellpadding='5'><tr><td  valign='top'><ul>";
            }
        }
        else
        {
            LitCacheView.Text += "<table style='width:100%' border='0' cellpadding='5'><tr><td style='width:100%;' valign='top'><ul >";
        }

        DataSet ds = null;
        string ros = ro.GetSelfSettingRole();

        if (DtTop != null)
        {
            if (DtTop.Rows.Count > 0)
            {
                LitCacheView.Text += "<li style='color:red;font-size:16px;font-weight:bold;background-color:#eee;line-height:28px;border-top:2px red solid;height: 28px;'> <img src='images/top.gif' border='0' title='精华' style='margin-top:3px;'/>&nbsp;&nbsp;精华主题</li><li style='line-height:5px;height:5px'></li>";
                string temp_folder = "";
                string temp_content = "";

                for (int i = 0; i < DtTop.Rows.Count; i++)
                {
                    edit = false;
                    bool view = false;
                    switch (SM)
                    {
                        case ShowMode.Article:
                        case ShowMode.ArticleSon:
                        case ShowMode.Border:
                            ds = cps.GetList("p_table='a' and p_pid=" + DtTop.Rows[i]["ArtId"].ToString());
                            break;
                        case ShowMode.GetTop:
                            ds = cps.GetList("p_table='t' and p_pid=" + DtTop.Rows[i]["TypeId"].ToString());
                            break;
                    }

                    edit = ds.Tables[0].Select(ros + " and p_type='1'", "p_id").Length > 0 ? true : false;
                    view = ds.Tables[0].Select(ros + " and p_type='0'", "p_id").Length > 0 ? true : false;
                    switch (SM)
                    {
                        case ShowMode.Type:

                            Append(ref temp_folder,ref temp_content, DtTop.Rows[i]["ArtTopic"].ToString(), id, DtTop.Rows[i]["ArtId"].ToString(), Convert.ToDateTime(DtTop.Rows[i]["ModfiyTime"]).ToString("yy-MM-dd"), DtTop.Rows[i]["ArtFormat"].ToString(), edit, view, DtTop.Rows[i]["Audit"].ToString(), false, DtTop.Rows[i]["ArtSummary"].ToString(), DtTop.Rows[i]["ArtKeys"].ToString(), NeedEdit, ShowLength, "True");
                            break;
                        case ShowMode.Border:
                        case ShowMode.GetTop:
                            Append(ref temp_folder, ref temp_content, DtTop.Rows[i]["ArtTopic"].ToString(), id, DtTop.Rows[i]["ArtId"].ToString(), Convert.ToDateTime(DtTop.Rows[i]["ModfiyTime"]).ToString("yy-MM-dd"), DtTop.Rows[i]["ArtFormat"].ToString(), edit, view, DtTop.Rows[i]["Audit"].ToString(), true, DtTop.Rows[i]["ArtSummary"].ToString(), DtTop.Rows[i]["ArtKeys"].ToString(), NeedEdit, ShowLength, "True");
                            break;
                        case ShowMode.Article:
                            AppendArticle(ref temp_folder, ref temp_content, DtTop.Rows[i]["ArtTopic"].ToString(), id, DtTop.Rows[i]["ArtId"].ToString(), Convert.ToDateTime(DtTop.Rows[i]["ModfiyTime"]).ToString("yy-MM-dd"), DtTop.Rows[i]["ArtFormat"].ToString(), edit, view, DtTop.Rows[i]["Audit"].ToString(), true, DtTop.Rows[i]["ArtSummary"].ToString(), DtTop.Rows[i]["ArtKeys"].ToString(), NeedEdit, ShowLength, "True");
                            break;
                    }
                }
                LitCacheView.Text += temp_folder;
                LitCacheView.Text += temp_content;
                LitCacheView.Text += "<li><div style='border-top:dashed 1px #999;width:100%; height:2px;line-height:2px'></div></li><li></li>";
            }
        }

        if (dt != null)
        {
            if (dt.Rows.Count > 0)
            {
                string temp_folder = "";
                string temp_content = "";

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    edit = false;
                    bool view = false;
                    switch (SM)
                    {
                        case ShowMode.Article:
                        case ShowMode.ArticleSon:
                        case ShowMode.Border:
                        case ShowMode.Type:
                            ds = cps.GetList("p_table='a' and p_pid=" + dt.Rows[i]["ArtId"].ToString());
                            break;
                        case ShowMode.GetTop:
                            ds = cps.GetList("p_table='t' and p_pid=" + dt.Rows[i]["TypeId"].ToString());
                            break;
                    }



                    edit = ds.Tables[0].Select(ros + " and p_type='1'", "p_id").Length > 0 ? true : false;
                    view = ds.Tables[0].Select(ros + " and p_type='0'", "p_id").Length > 0 ? true : false;
                    switch (SM)
                    {
                        case ShowMode.Type:
                            Append(ref temp_folder,ref temp_content, dt.Rows[i]["ArtTopic"].ToString(), id, dt.Rows[i]["ArtId"].ToString(), Convert.ToDateTime(dt.Rows[i]["ModfiyTime"]).ToString("yy-MM-dd"), dt.Rows[i]["ArtFormat"].ToString(), edit, view, dt.Rows[i]["Audit"].ToString(), false, dt.Rows[i]["ArtSummary"].ToString(), dt.Rows[i]["ArtKeys"].ToString(), NeedEdit, ShowLength, "False");
                            break;
                        case ShowMode.Border:
                        case ShowMode.GetTop:
                            Append(ref temp_folder, ref temp_content, dt.Rows[i]["ArtTopic"].ToString(), id, dt.Rows[i]["ArtId"].ToString(), Convert.ToDateTime(dt.Rows[i]["ModfiyTime"]).ToString("yy-MM-dd"), dt.Rows[i]["ArtFormat"].ToString(), edit, view, dt.Rows[i]["Audit"].ToString(), true, dt.Rows[i]["ArtSummary"].ToString(), dt.Rows[i]["ArtKeys"].ToString(), NeedEdit, ShowLength, "False");
                            break;
                        case ShowMode.Article:
                            AppendArticle(ref temp_folder, ref temp_content, dt.Rows[i]["ArtTopic"].ToString(), id, dt.Rows[i]["ArtId"].ToString(), Convert.ToDateTime(dt.Rows[i]["ModfiyTime"]).ToString("yy-MM-dd"), dt.Rows[i]["ArtFormat"].ToString(), edit, view, dt.Rows[i]["Audit"].ToString(), true, dt.Rows[i]["ArtSummary"].ToString(), dt.Rows[i]["ArtKeys"].ToString(), NeedEdit, ShowLength, "False");
                            break;
                    }
                }

                LitCacheView.Text += temp_folder;
                LitCacheView.Text += temp_content;
            }
        }

        if (img != "")
        {
            if (imgs[0] == "l")
            {
                switch (SM)
                {
                    case ShowMode.Type:
                        LitCacheView.Text += "</ul></td></tr></table></div><a href='ViewListBorder.aspx?id=" + id + "&check=" + ro.GetMd5Str(id + "check" + edit.ToString()) + "' class='bluebtn' style='float:right'>更多</a><br/><br/></div>";
                        break;
                    case ShowMode.Border:
                        LitCacheView.Text += "</ul></td></tr></table></div><a href='ViewListArticle.aspx?bid=" + id + "&pid=0&check=" + ro.GetMd5Str(id + "check" + edit.ToString()) + "' class='bluebtn' style='float:right'>更多</a><br/><br/></div>";
                        break;
                    case ShowMode.Article:
                        LitCacheView.Text += "</ul></td></tr></table></div><br/><br/></div>";
                        break;

                }
            }
            else
            {
                switch (SM)
                {
                    case ShowMode.Type:
                        LitCacheView.Text += "</ul></td><td style='width:200px;' valign='top'><img src=" + imgs[1] + " style='width:200px;height:150px;'></td></tr></table></div><a href='ViewListBorder.aspx?id=" + id + "&check=" + ro.GetMd5Str(id + "check" + edit.ToString()) + "' class='bluebtn' style='float:right'>更多</a><br/><br/></div>";
                        break;
                    case ShowMode.Border:
                        LitCacheView.Text += "</ul></td><td style='width:200px;' valign='top'><img src=" + imgs[1] + " style='width:200px;height:150px;'></td></tr></table></div><a href='ViewListArticle.aspx?bid=" + id + "&pid=0&check=" + ro.GetMd5Str(id + "check" + edit.ToString()) + "' class='bluebtn' style='float:right'>更多</a><br/><br/></div>";
                        break;
                    case ShowMode.Article:
                        LitCacheView.Text += "</ul></td><td style='width:200px;' valign='top'><img src=" + imgs[1] + " style='width:200px;height:150px;'></td></tr></table></div><br/><br/></div>";
                        break;
                }
            }
        }
        else
        {
            switch (SM)
            {
                case ShowMode.Type:
                    LitCacheView.Text += "</ul></td></tr></table></div><a href='ViewListBorder.aspx?id=" + id + "&check=" + ro.GetMd5Str(id + "check" + edit.ToString()) + "' class='bluebtn' style='float:right'>更多</a><br/><br/></div>";
                    break;
                case ShowMode.Border:
                    LitCacheView.Text += "</ul></td></tr></table></div><a href='ViewListArticle.aspx?bid=" + id + "&pid=0&check=" + ro.GetMd5Str(id + "check" + edit.ToString()) + "' class='bluebtn' style='float:right'>更多</a><br/><br/></div>";
                    break;
                case ShowMode.Article:
                    LitCacheView.Text += "</ul></td></tr></table></div><br/><br/></div>";
                    break;
                case ShowMode.GetTop:
                    LitCacheView.Text += "</ul></td></tr></table></div></div>";
                    break;
            }
        }
    }

    private void BindPager(int num, DataTable dt, int NowPage, int top)
    {
        apg.CurrentPageIndex = NowPage;
        apg.PageSize = top;
        apg.RecordCount = num;
        Pg.Visible = true;
    }

    private void Append(ref string temp_folder, ref string temp_content, string topic, string type, string id, string time, string format, bool edit, bool view, string pid, bool IsSum, string Sum, string Keys, bool NeedEdit, int ShowLength, string IsTop)
    {
        if (!edit && !view)
        {
        }
        else
        {
            string SpEdit = "";
            string New = "";
            string SumStr = "<br/><span style='line-height:20px;color:#999'>";
            string img = "<img src='images/treeicon/" + format + ".jpg'/>";
            string top = "";
            string endtop = "link";
            if (pid != "")
            {
                pid = (Convert.ToBoolean(pid)).ToString();
            }
            else
            {
                pid = "False";
            }
            if (edit)
            {
                string pd = pid.ToString() == "True" ? "1" : "0";
                SpEdit = "<span style=' cursor:hand;color:blue' onclick=\"LightBox('" + StrReplace(topic) + "','Admin/ViewControl.aspx?action=edit&type=b&id=" + id + "','900','700','',true);return false\"><img src='images/edit.gif'/> 修改</span>";

            }
            if (Convert.ToDateTime(time).AddDays(15) >= DateTime.Now && Request.Cookies["a_" + id] == null)
            {
                New = "<img src='images/new.gif' border='0'/>";
            }

            if (IsTop != "")
            {
                if (IsTop == "True")
                {
                    //top = "<img src='images/top.gif' border='0' title='精华'/>";
                    //endtop = "toplink";
                }

            }
            if (IsSum)
            {
                //if (Sum.Trim().Length > 0)
                //{
                //    if (Sum.Trim().Length > 50)
                //    {
                //        SumStr += "<span >" + Sum.Substring(0, 50) + "...</span><br/>";
                //    }
                //    else
                //    {
                //        SumStr += "<span >" + Sum + "...</span><br/>";
                //    }
                //}
                //if (Keys.Trim().Length > 0)
                //{
                //    SumStr += "关键字：<span style='color:red;'> " + Keys + " </span>";
                //}


                SumStr += "</span>";

            }
            else
            {
                SumStr = "";
            }

            if (NeedEdit)
            {
                temp_content += "<li> " + top + " " + img + " <a href='View.aspx?Id=" + id + "&edit=" + ro.GetMd5Str(id + "edit" + edit.ToString()) + "&view=" + ro.GetMd5Str(id + "view" +
                    view.ToString()) + "&check=" + ro.GetMd5Str(id + "check" + pid.ToString()) + "' class=' " + endtop + "' title='" + StrReplace(topic) + "'>" + StrReplace(topic, ShowLength) + "</a>  " + New + " <span style='color:#999;font-family:Arial;'>（" +
                    time + "） </span>" + SpEdit + SumStr + "</li>";
            }
            else
            {
                temp_content += "<li> " + top + "" + img + " <a href='View.aspx?Id=" + id + "&edit=" + ro.GetMd5Str(id + "edit" + edit.ToString()) + "&view=" + ro.GetMd5Str(id + "view" +
                    view.ToString()) + "&check=" + ro.GetMd5Str(id + "check" + pid.ToString()) + "' class=' " + endtop + "' title='" + StrReplace(topic) + "'>" + StrReplace(topic, ShowLength) + "</a>  " + New + " <span style='color:#999;font-family:Arial;'>（" +
                    time + "） </span>" + SumStr + "</li>";
            }
        }
    }

    private void AppendArticle(ref string temp_folder,ref string temp_content, string topic, string type, string id, string time, string format, bool edit, bool view, string pid, bool IsSum, string Sum, string Keys, bool NeedEdit, int ShowLength, string IsTop)
    {

        if (!edit && !view)
        {
        }
        else
        {
            if (format != "1")
            {
                string SpEdit = "";
                string New = "";
                string SumStr = "<br/><span style='line-height:20px;color:#999'>";
                string img = "<img src='images/treeicon/" + format + ".jpg'/>";
                string top = "";
                string endtop = "link";
                if (pid != "")
                {
                    pid = Convert.ToBoolean(pid).ToString();
                }
                else
                {
                    pid = "False";
                }
                if (edit)
                {
                    string pd = pid.ToString() == "True" ? "1" : "0";
                    // SpEdit = "<span style=' cursor:hand;' onclick=\"var diag=new Dialog();diag.Width =780;diag.Height=650;diag.Title='" + topic +
                    //     "';diag.URL='Admin/ViewControl.aspx?action=edit&id=" + id + "&check=" + pd + "';diag.show();" + "return false\"><img src='images/edit.gif'/></span>";
                    SpEdit = "<span style=' cursor:hand;color:blue' onclick=\"LightBox('" + StrReplace(topic) + "','Admin/ViewControl.aspx?action=edit&type=a&id=" + id + "','900','700','',true);return false\"><img src='images/edit.gif'/> 修改</span>";

                }
                if (Convert.ToDateTime(time).AddDays(15) >= DateTime.Now && Request.Cookies["a_" + id] == null)
                {
                    New = "<img src='images/new.gif' border='0'/>";
                }

                if (IsTop != "")
                {
                    if (IsTop == "True")
                    {
                        //top = "<img src='images/top.gif' border='0' title='精华'/>";
                        //endtop = "toplink";
                    }

                }
                if (IsSum)
                {
                    //if (Sum.Trim().Length > 0)
                    //{
                    //    if (Sum.Trim().Length > 50)
                    //    {
                    //        SumStr += "<span >" + Sum.Substring(0, 50) + "...</span><br/>";
                    //    }
                    //    else
                    //    {
                    //        SumStr += "<span >" + Sum + "...</span><br/>";
                    //    }
                    //}
                    //if (Keys.Trim().Length > 0)
                    //{
                    //    SumStr += "关键字：<span style='color:red;'> " + Keys + " </span>";
                    //}


                    SumStr += "</span>";

                }
                else
                {
                    SumStr = "";
                }

                if (NeedEdit)
                {
                    temp_content += "<li> " + top + " " + img + " <a href='View.aspx?Id=" + id + "&edit=" + ro.GetMd5Str(id + "edit" + edit.ToString()) + "&view=" +
                            ro.GetMd5Str(id + "view" + view.ToString()) + "&check=" + ro.GetMd5Str(id + "check" + pid.ToString()) + "' class=' " + endtop + "' title='" + StrReplace(topic) + "'>" + StrReplace(topic, ShowLength) + "</a>　 " + New + " <span style='color:#999;font-family:Arial;'> （" +
                            time + "） </span>" + SpEdit + SumStr + "</li>";
                }
                else
                {
                    temp_content += "<li> " + top + " " + img + " <a href='View.aspx?Id=" + id + "&edit=" + ro.GetMd5Str(id + "edit" + edit.ToString()) + "&view=" +
                            ro.GetMd5Str(id + "view" + view.ToString()) + "&check=" + ro.GetMd5Str(id + "check" + pid.ToString()) + "' class=' " + endtop + "' title='" + StrReplace(topic) + "'>" + StrReplace(topic, ShowLength) + "</a>　 " + New + " <span style='color:#999;font-family:Arial;'> （" +
                            time + "） </span>" + SumStr + "</li>";
                }

            }
            else
            {
                temp_folder += "<li><img src='images/treeicon/mappe.gif'/> <a href='ViewListArticle.aspx?pid=" + id + "&check=" + ro.GetMd5Str(id + "check" + edit.ToString()) + "' class='link'>" + topic + "</a> </li>";
            }
        }
    }

    private string StrReplace(string Str, int ShowLength)
    {
        if (ShowLength != -1)
        {
            Str = Str.Replace("\"", "＂");
            if (Str.Length > ShowLength)
            {
                return Str.Substring(0, ShowLength) + "...";
            }
            else
            {
                return Str;
            }
        }
        else
        {
            return Str.Replace("\"", "＂");
        }
    }

    private string StrReplace(string Str)
    {

        return Str.Replace("\"", "＂");

    }



}
